'use strict';

const db = uniCloud.database();
exports.main = async (event, context) => {
	//event为客户端上传的参数
	// console.log('event : ', event)
	const {userId,articleId} = event;
	
	const data = await db.collection('user').doc(userId).get();
	
	let articleArr = data.data[0].like_article;
	if(articleArr.indexOf(articleId)==-1){
		articleArr.push(articleId)
	}
	
	await db.collection('user').doc(userId).update({
		like_article:articleArr
	})
	
	//返回数据给客户端
	return {
		code:0
	}
};
